package com.leyou.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiuer
 * @description 商品分类服务控制层
 * @create 2019/6/23 18:47
 */
@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    /**
     * @param pid pid  category表中 parent_id
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByPid(
            @RequestParam(value = "pid", defaultValue = "0") Long pid) {
        return ResponseEntity.ok(categoryService.queryCategoryByPid(pid));
    }

    //http://api.leyou.com/api/item/category/of/brand/?id=6742

    /**
     * 根据bid查询一个品牌对应的所有分类
     *
     * @param bid 商品id
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBid(@RequestParam("id") Long bid) {
        return ResponseEntity.ok(categoryService.queryCategoryByBid(bid));
    }

    /**
     * 根据商品分类id集合查询分类名称
     */
    @GetMapping("list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(categoryService.queryCategoryByCids(ids));
    }
}
